<template>
    <div class="transfer">
        <v-navbar/>
        <div class="transfer_container">
            <div class="transfer_formInput">

                <div class="tf_formLabel tf_formB">
                    <div class="tf_inputTitle">
                        <span>请选择转账资产</span>
                    </div>
                    <div class="tf_inputCon tf_radio">
                        <RadioGroup v-model="single">
                            <Radio v-for="(v,i) in Radio" :key="i" :value='v.value' :label='v.label' />
                        </RadioGroup>
                    </div>
                </div>

                <div class="tf_formLabel tf_formB">
                    <div class="tf_inputTitle">
                        <span>收款人帐号</span>
                    </div>
                    <div class="tf_inputCon">
                        <input class="tf_input" maxlength="11" type="text" v-model="toPhone">
                    </div>
                </div>

                <div class="tf_formLabel">
                    <div class="tf_inputTitle">
                        <span>转账金额</span>
                    </div>
                    <div class="tf_inputCon">
                        <input class="tf_input" type="text" placeholder="(必须为100的整倍数)" v-model="money">
                    </div>
                </div>

            </div>

            <div class="tf_btn" @click="e_dotransfer">
                <v-button :text="buttonText"></v-button>
            </div>
        </div>
        <t-pwdbox v-if="doTransfer" @closepwdbox='closepwdbox' :carryData="carryData"/>
    </div>
</template>

<script>
import navbar from '@c/navbar/navbar'
import Button from '@c/button/button'
import tfpwdbox from './tfpwdbox'
import { mapState, mapMutations } from 'vuex'

const BALANCE = '余额'
const INREGEAL = '积分'

export default {
	name: 'transfer',
	data() {
		return {
			single: '',
			Radio: [
				{
					value: 1,
					label: BALANCE,
				},
				{
					value: 0,
					label: INREGEAL,
				},
			],
			toPhone: '',//收款人手机号
			money: '', //金额
			buttonText: '确认转账',
			doTransfer: false,
			carryData: {}
		}
	},

	components: {
		'v-navbar': navbar,
		'v-button': Button,
		't-pwdbox': tfpwdbox,
	},

	computed: {
		...mapState(['wtitle', 'rback', 'signed']),
		_getRadioType() {
			if (this.single === BALANCE) {
				return 1
			} else if (this.single === INREGEAL) {
				return 0
			} else {
				return ''
			}
		}
	},

	methods: {
		...mapMutations(['WTITLE', 'RBACK', 'USERSINGED']),
		// 点击转账
		e_dotransfer() {
			this._dotransferCheck()
		},
		// 关闭密码框
		closepwdbox(a) {
			this.doTransfer = a
		},
		_dotransferCheck() {
			let sendData = {
				userId: window.localStorage.userId,
				type: this._getRadioType,
				toPhone: this.toPhone,
				money: this.money,
			}
			if (sendData.type === '') {
				this.$Message.warning('请选择转账资产')
				return
			}
			if (sendData.toPhone === '') {
				this.$Message.warning('请输入收款人账号')
				return
			}
			if (sendData.money === '') {
				this.$Message.warning('请输入转账金额')
				return
			}

			this.carryData = sendData
			if (window.localStorage.getItem('tradPassword') == 'false') {
                this.$router.push('/setPay')
                return
            }
			this.doTransfer = true
		}
	},
	created() {
		this.WTITLE('转账')
		this.RBACK(true)
	},
	mounted() {},
}
</script>
<style>
</style>
